﻿<%@ Page Title="订单列表" Language="C#" MasterPageFile="~/Wap/Shop/ShopSite.Master" AutoEventWireup="true" CodeBehind="OrderList.aspx.cs" Inherits="ZLCMS.Web.Wap.Shop.OrderList" %>
<%@ Register src="Footer.ascx" tagname="Footer" tagprefix="uc1" %>
<%@ Import Namespace ="ZLCMS.Business.Util" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
	#nav li{ border-left:1px solid #ddd;box-sizing: border-box;  -webkit-box-sizing: border-box; -moz-box-sizing: border-box; border-bottom:1px solid #ddd;}
	#nav li:nth-child(1){ border-left:none;}
	#navFixed .ui-navbar ul li a{ line-height: 24px;}
	#navFixed .ui-navbar ul li a.ui-btn-active{ color:#f9384d; border-bottom-color:#f9384d;}
    .givePresent{background: #fff;min-height:34px; line-height:20px; font-size:12px; border-top:1px dashed #eee; margin-top: 5px;}
    .givePresent .give{display: inline-block;  font-size:12px;}
    .givePresent .man {margin-left:15px;}
    .all_order .foot{margin:0;}
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="pages" runat="server">

<!--S page -->

<div data-role="page" id="mypage">

	<!--S header -->
	<div data-role="header">
	</div>
    <!--E header -->
	
    <!--S content -->
	<div role="main" class="ui-content">
    
    	<!--s nav-->
        <div id="navFixed" >
        <div id="nav">
        	<div data-role="navbar" nav="navFixed">
              <ul>
                <li><a href="#" data-theme="f" <%=ActiveStatus=="all"?"class='ui-btn-active'":"" %> onclick="queryData({});">全部订单</a></li>
                <li><a href="#" data-theme="f" <%=ActiveStatus=="pay"?"class='ui-btn-active'":"" %> onclick="queryData({PayStatus:'0', CancelStatus:'0'});">待支付</a></li>
                <li><a href="#" data-theme="f" <%=ActiveStatus=="shipping"?"class='ui-btn-active'":"" %> onclick="queryData({PayStatusFilter:{Name:'PAY_STATUS',ParameterKey:'PAY_STATUS',Value:'0',CompairType:'NotEqual'}, CancelStatus:'0',FinishedStatus:'0'});">待收货</a></li>
                <%--<li><a href="#" data-theme="f" <%=ActiveStatus==""?"class='ui-btn-active'":"" %> onclick="queryData({FinishedStatus:'1', CancelStatus:'0'});">已完成</a></li>--%>
              </ul>
            </div>
        </div>
        </div>
        <!--e nav-->
       
       <div class="listviewHandler">

       </div>
       <div style="display:none">
        <button id="btnMore" data-icon="refresh" style="width: 95%; margin-left: auto; margin-right: auto;">显示更多</button>
       </div>

        
 	</div>
    <!--E content -->
	
    <!--S footer -->
	<div data-role="footer" data-position="fixed" data-tap-toggle="false">
    
                <uc1:Footer ID="Footer1" runat="server" MenuId="M" />    
    </div>
    <!--E footer -->
</div>
<!--E page -->

<script src="js/order.js?v=0615" type="text/javascript"></script>
<script src="/wap/lib/common/listviewHandler.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        $('#navFixed a.ui-btn-active').click();
    });

    function queryData(data) {
        var param = $.extend({}, { MemberAccount: '<%=CurrentMemberAccount %>' }, data);
        var handler = $('.listviewHandler').listviewHandler();
        handler.initialize({
            loaderBtn: $('#btnMore'), //加载数据按钮（点击加载下一页）
            emptyHtml: '<p class="more">-- 没有订单信息 --</p>', //无记录时显示此html
            itemTemplate: '        <div class="all_order">' +
        	'<div class="top">' +
            	'<div class="left">' +
                	'<p>{OrderTime}</p>' +
               ' </div>' +
                '<div class="right"><span  class="btn">{StatusText}</span></div>' +
             '{ElapsedTips}' +
               ' <div class="clear"></div>' +
           ' </div>' +
           '<a href="OrderDetail.aspx?no={OrderNo}" data-ajax="false">{ProductListHtml}</a>' +
           '{GiftHtml}' +
        	'<div class="foot">' +
            	'<div class="left">' +
                	'<p><font>￥{PaymentPrice}{PackageCount}</font></p>' +
               ' </div>' +
                '<div class="right">{ActionHtml}</div>' +
               ' <div class="clear"></div>' +
           ' </div>' +
       ' </div>', //项模板
            pageIndex: 1, //页码（从1起算）
            pageSize: 10, //页大小
            totalCount: 999, //总记录数
            itemHandler: function (data, itemTemplate, container) {//数据各项处理
                if (data.PackageStatus == '1') {
                    data.PackageCount = '，共' + data.PackageList.length + '个包裹 ';
                } else {
                    data.PackageCount = '';
                }
                data.StatusText = '--';
                data.ActionHtml = '';
                data.ElapsedTips = '';
                //data.OrderTime = data.OrderTime.substr(0, 10);
                if (data.CancelStatus == '1') {
                    data.StatusText = '[已取消]';
                } else if (data.PayStatus == '0' && data.CancelStatus == '0') {
                    data.StatusText = '[待支付]';

                    var orderTime = new Date(Date.parse(data.OrderTime.replace(/-/g, "/")));
                    var cancelTime = new Date();
                    cancelTime.setTime(orderTime.getTime() + 1000 * parseInt('<%=ParamKit.GetValue("SystemConfig", "OrderTimeout", "60") %>') * 60);

                    data.ElapsedTips = '<div class="ordertips">此单将于下单30分钟后取消，请及时支付</div>';
                    //取消，去支付
                    data.ActionHtml = '<a href="#" onclick="payOrder($(this),\'{MemberAccount}\', \'{PaymentNo}\')" class="btn">去支付</a><a href="#" class="btn newbtn" onclick="cancelOrder($(this),\'{MemberAccount}\', \'{OrderNo}\');">取消</a>'
                        .format({ MemberAccount: '<%=CurrentMemberAccount %>', PaymentNo: data.PaymentNo, OrderNo: data.OrderNo });
                } else if (data.PayStatus != '0' && data.CancelStatus == '0' && data.FinishedStatus == '0') {
                    if (data.ConfirmedStatus == '0') {
                        data.StatusText = '[已支付]';
                        //可以取消订单
                        if (data.SplitStatus == "9") {
                            data.ActionHtml = '<a href="#" class="btn newbtn" onclick="cancelOrder($(this), \'{MemberAccount}\', \'{OrderNo}\');">取消</a>'
                            .format({ MemberAccount: '<%=CurrentMemberAccount %>', OrderNo: data.OrderNo });
                        }

                    } else if (data.ShippingStatus == '0') {
                        data.StatusText = '[配货中]';
                        data.ActionHtml = '<a href="/wap/shop/SubmitReturnApply.aspx?no={OrderNo}" class="btn newbtn2" data-ajax="false" >申请售后</a><a href="OrderDetail.aspx?no={OrderNo}" class="btn newbtn" data-ajax="false" >查询物流</a>'
                        .format({ MemberAccount: '<%=CurrentMemberAccount %>', OrderNo: data.OrderNo });
                    } else if (data.ShippingStatus == '1') {
                        data.StatusText = '[已发货]';
                        data.ActionHtml = '<a href="/wap/shop/ReturnablesList.aspx?no={OrderNo}" class="btn newbtn2" data-ajax="false" >申请售后</a><a href="OrderDetail.aspx?no={OrderNo}" class="btn newbtn" data-ajax="false">查询物流</a>'
                        .format({ MemberAccount: '<%=CurrentMemberAccount %>', OrderNo: data.OrderNo, ShippingType: data.ShippingType, ShippingNo: data.ShippingNo });
                    }
                } else if (data.CancelStatus == '0' && data.FinishedStatus == '1') {
                    data.StatusText = '[已完成]';
                    if (data.CommentStatus == '1') {
                        //<a href="#" class="btn" onclick="deleteOrder($(this), \'{MemberAccount}\', \'{OrderNo}\');">删除</a>
                        data.ActionHtml = '<a href="/wap/shop/ReturnablesList.aspx?no={OrderNo}" class="btn newbtn2" data-ajax="false" >申请售后</a><a data-ajax="false" href="CommentCenter.aspx?ono={OrderNo}" class="btn newbtn">写评价</a>'
                            .format({ MemberAccount: '<%=CurrentMemberAccount %>', OrderNo: data.OrderNo });

                    } else {
                        //<a href="#" class="btn" onclick="deleteOrder($(this), \'{MemberAccount}\', \'{OrderNo}\');">删除</a>
                        data.ActionHtml = '<a href="/wap/shop/ReturnablesList.aspx?no={OrderNo}" class="btn newbtn2" data-ajax="false" >申请售后</a>'
                            .format({ MemberAccount: '<%=CurrentMemberAccount %>', OrderNo: data.OrderNo });
                        if (data.AppendStatus == "1" && data.CommentStatus == "0") {
                            data.ActionHtml += '<a data-ajax="false" href="CommentCenter.aspx?ono={OrderNo}&cs=1" class="btn newbtn">追评</a>'
                            .format({ OrderNo: data.OrderNo });
                        }
                    }
                }

                try {
                    var actionList = $.parseJSON(data.OrderActions);
                    $(actionList).each(function () {
                        data.ActionHtml = '<a data-ajax="false" href="{Url}" class="btn">{Name}</a>'.format(this)
                        + data.ActionHtml;
                    });
                } catch (e) { }

                data.ProductListHtml = '';
                productListHtml = ' <div class="bottom">' +
            	'<div class="left"><img src="{ThumbnailImg}"></div>' +
              '  <div class="right">' +
               ' 	<h2>{ProductName}</h2>' +
                '<p>{SkuHtml}</p><p><font>￥{SalePrice} * {Counter}件</font> </p>' +
               ' </div>' +
               ' <div class="clear"></div>' +
           ' </div>';
                $(data.ProductList).each(function () {
                    this.ThumbnailImg = firstThumbnail(this.ThumbnailImg);
                    var skuData = $.parseJSON(this.SkuParamCode);
                    var skuHtml = '';
                    $(skuData).each(function () { skuHtml += '<span>' + this.ItemName + '</span>'; });
                    this.SkuHtml = skuHtml;
                    data.ProductListHtml += productListHtml.format(this);
                });
                data.GiftHtml = "";
                if (data.GiftList && data.GiftList != "[]") {
                    var giftName = "";
                    var giftlist = $.parseJSON(data.GiftList);
                    $(giftlist).each(function () {
                        if (this.DeptCode) {
                            $(this.GiftList).each(function () {
                                if (this.Counter > 0) {
                                    giftName += this.ProductName + "×" + this.Counter + "&nbsp;&nbsp;";
                                } else {
                                    giftName += this.ProductName  + "&nbsp;&nbsp;";
                                }

                            });
                        } else {
                            //                        $(this.GiftList).each(function () {
                            if (this.Counter > 0) {
                                giftName += this.ProductName + "×" + this.Counter + "&nbsp;&nbsp;";
                            } else {
                                giftName += this.ProductName + "&nbsp;&nbsp;";
                            }
                            //                        });
                        }
                    });
                    data.GiftHtml = '<div class="givePresent"><span class="give">[&nbsp;赠品&nbsp;]</span><span class="man">' + giftName + '</span></div>';
                }
                return itemTemplate.format(data);
            },
            command: 'Member.LoadOrderList',
            parameter: param
        });
        handler.nextPage();
    }

    $(function () {
        $(window).scroll(function () {
            //当内容滚动到底部时加载新的内容

            if ($(this).scrollTop() + $(window).height() + 20 >= $(document).height() && $(this).scrollTop() > 20) {
                //当前要加载的页码
                $('#btnMore').click();
            }
        });
    });
</script>
</asp:Content>
